import Vue from 'vue'
import Vuex from 'vuex'
import baseApi from '@/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: {}
  },
  mutations: {
    setUserInfo(state, info) {
      state.userInfo = info
    }
  },
  actions: {
    getUserInfo(state) {
      return new Promise((resolve, reject) => {
        baseApi
          .getUserInfo()
          .then((res) => {
            if (res.httpStatusCode === 200 && res.success) {
              state.commit('setUserInfo', res.model)
              resolve(res)
            } else {
              reject(res)
            }
          })
          .catch((err) => {
            console.log(err, 'err')
            reject(err)
          })
      })
    }
  },
  modules: {}
})
